home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
hypercrd
/
hc1_2_x
/
onlnrfpr.sit
/
Parse Functions
/
background_3763.txt
< prev
next >
Wrap
Text File
|
1991-06-18
|
11KB
|
407 lines
-- background: 3763 from stack: in
-- bmap block id: 4463
-- flags: 0000
-- background id: 0
-- name: Protos
-- part 1 (field)
-- low flags: 04
-- high flags: 0002
-- rect: left=75 top=2 right=18 bottom=187
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 12
-- part name: FileName
-- part 2 (field)
-- low flags: 04
-- high flags: 0002
-- rect: left=250 top=2 right=18 bottom=411
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 12
-- part name: Returns
-- part 3 (field)
-- low flags: 04
-- high flags: 0007
-- rect: left=75 top=21 right=73 bottom=411
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 12
-- part name: Prototype
-- part 4 (button)
-- low flags: 00
-- high flags: 2000
-- rect: left=382 top=217 right=240 bottom=416
-- title width / last selected line: 0
-- icon id / first selected line: 1013 / 1013
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Next
----- HyperTalk script -----
on mouseUp
go to next card
end mouseUp
-- part 5 (button)
-- low flags: 00
-- high flags: 2000
-- rect: left=0 top=216 right=240 bottom=25
-- title width / last selected line: 0
-- icon id / first selected line: 1014 / 1014
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Prev
----- HyperTalk script -----
on mouseUp
go to previous card
end mouseUp
-- part 6 (button)
-- low flags: 00
-- high flags: A004
-- rect: left=34 top=218 right=237 bottom=193
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Read Header Files
----- HyperTalk script -----
on mouseUp
put false into multi
put 0 into fileNumber
answer "Shall I go straight on and export the data after IΓÇÖve read it in?" with "Yes", "No"
if it is "Yes" then
put true into batchMode
else
put false into batchMode
end if
answer "Parse one file or the list from a folder?" with "Cancel", "Many", "One"
if it is "Cancel" then exit mouseUp
if it is "One" then
answer file "C header file to parse:" of type "TEXT"
if it is empty then exit mouseUp
put it into fileName
-- this function is in home and strips off the path
put lastHCItem(":", fileName) into shortFileName
put getPath(fileName) into path
end if
if it is "Many" then
put true into multi
put 1 into fileNumber
answer file "Open any file in the source folder:" of type "TEXT"
if it is empty then exit mouseUp
put it into fileName
-- this gets the path from the pull file and path
put getPath(fileName) into path
put files(path) into background fld "Files"
put background fld "files" into fileList
end if
repeat
if multi then
-- get the next file name from the list
put line fileNumber of fileList into fileName
if fileName is empty then
if batchMode then
doExport "New TextBase"
end if
beep
beep
beep
exit mouseUp
end if
put fileName into shortFileName
put path before fileName
put fileNumber + 1 into fileNumber
end if
open file fileName
put "Reading file number: " & fileNumber -1 & " “" &fileName & "”…"
read from file fileName until return
go to the last card of background "Protos"
repeat while it is not empty
put it into line
set cursor to busy
if isCfunction(line) then
-- collect the function
put offset(")", line) into closeBracketAt
-- test for multi-line functions
if closeBracketAt is 0 then
read from file fileName until ")"
put line & it & ";" into funcLine
else
-- handle single line function prototypes
put character 1 to closeBracketAt of line & ";" into funcLine
end if
-- replaces tabs with spaces
put stripTabs(funcLine) into funcLine
-- remove the return types
put offset("(", funcLine) into openBracketAt
if openBracketAt is not zero then
-- scan back over spaces to find the function name
repeat with i = openBracketAt down to 1
if character i of funcLine is not space then exit repeat
end repeat
-- scan back until we find the space before the function name
repeat with i = i - 3 down to 1
if character i of funcLine is space then exit repeat
end repeat
put character 1 to i of funcLine into returnType
delete character 1 to i of funcLine
end if
-- now prepare to put the information in a card
doMenu "New Card"
put shortFileName into background field "FileName"
if word 1 of returnType is "pascal" then
delete word 1 of returnType
end if
if word 1 of returnType is empty then
put "void" into returnType
end if
put returnType into background field "Returns"
-- strip off leading spaces
repeat with i = 1 to the number of chars in funcLine
if character 1 of funcLine is space or character 1 of funcLine is tab then
delete character 1 of funcLine
else
exit repeat
end if
end repeat
-- this gets rid of the carriage returns in the text
repeat with i = 1 to the number of words in funcLine
put word i of funcLine & space after background field "ProtoType"
end repeat
end if
read from file fileName until return
end repeat -- no more lines to read
if not multi then
close file fileName
hide msg
exit mouseUp
end if
close file fileName
end repeat -- reading multi files
end mouseUp
-- This should be improved but works well enough for the MPW headers
function isCfunction line
if word 1 of line is "pascal" then
return true
else
return false
end if
end isCfunction
-- replaces tabs with spaces
function stripTabs line
repeat with i = 1 to the number of characters in line
if character i of line is tab then
put space into character i of line
end if
end repeat
return line
end stripTabs
-- pinched from Home for completeness
function lastHCItem delim,theText
-- returns the portion of <theText> that follows the last <delim>
if delim is in theText then
put lastHCItem(delim,char offset(delim,theText) + 1 to length(theText) of theText) into theText
end if
return theText
end lastHCItem
function getPath theText
-- returns the portion of <theText> up to the last <delim>
repeat with i = the number of chars in theText down to 1
if character i of theText is ":" then exit repeat
end repeat
return character 1 to i of theText
end getPath
-- This sorts the cards by the function name
-- outputs the text to a file with the words wrapped at the
-- first word break after 65 characters are counted
-- output is: functionName(parameters); // type fileName.h
-- By: Peter Marks Access Informatics (02) 555 8414
on doExport fileName
sort by field "ProtoType"
put "Sorting the stack, please wait…" into msg
open file fileName
write "=" to file fileName
repeat with i = 1 to the number of cards in this stack
go to card i
set cursor to busy
put background fld "Prototype" & " // " & background fld "returns" & " <" & background fld "fileName" & ">|" into outLine
-- write out the text, wrapping at the first word after 61 chars wide
put false into break
repeat with j = 1 to the number of characters in outline
if break and character j of outline is space then
write return to file fileName
put false into break
end if
write character j of outline to file fileName
if j mod 61 is zero then
put true into break -- break when you can!
set cursor to busy
end if
end repeat
write return to file fileName
end repeat
write "=" to file fileName
close file fileName
beep
end doExport
-- part 7 (field)
-- low flags: 05
-- high flags: 0007
-- rect: left=85 top=139 right=203 bottom=217
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 12
-- part name: Files
-- part 8 (button)
-- low flags: 00
-- high flags: A004
-- rect: left=2 top=180 right=202 bottom=82
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 12
-- part name: Delete Cards
----- HyperTalk script -----
on mouseUp
answer "Do you want to delete all data from this stack?" with "Yes", "Cancel"
if it is "Cancel" then exit mouseUp
repeat with i = 2 to the number of cards in this stack
go to card 2
doMenu "Delete Card"
set cursor to busy
end repeat
end mouseUp
-- part 9 (button)
-- low flags: 00
-- high flags: A004
-- rect: left=199 top=218 right=237 bottom=379
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Export To OnBase
----- HyperTalk script -----
-- This sorts the cards by the function name
-- outputs the text to a file with the words wrapped at the
-- first word break after 65 characters are counted
-- output is: functionName(parameters); // type fileName.h
-- By: Peter Marks Access Informatics (02) 555 8414
on mouseUp
ask file "Name your export file:" with "TextBase"
if it is empty then exit mouseUp
put it into fileName
sort by field "ProtoType"
put "Sorting the stack, please wait…" into msg
open file fileName
write "=" to file fileName
repeat with i = 2 to the number of cards in this stack
go to card i
set cursor to busy
put background fld "Prototype" & " // " & background fld "returns" & " <" & background fld "fileName" & ">|" into outLine
-- write out the text, wrapping at the first word after 61 chars wide
put false into break
repeat with j = 1 to the number of characters in outline
if break and character j of outline is space then
write return to file fileName
put false into break
end if
write character j of outline to file fileName
if j mod 61 is zero then
put true into break -- break when you can!
set cursor to busy
end if
end repeat
write return to file fileName
end repeat
write "=" to file fileName
close file fileName
beep
end mouseUp